<template>
	<div class="edu-page-warp">
		<inner-breadcrumb v-model="pathKey" :path="path" v-show="pathKey!='main'"></inner-breadcrumb>
		<template v-if="pathKey=='main'">
			<condition-card @reset="reset" @search="onSubmit" label-width="120px">
				<el-row style="height: 50px;">
					<el-col :span="8" v-if="global.isAnyTeacher">
						<el-form-item :label="$t('管理部门')">
							<el-select v-model="queryForm.managerDeptId" style="width: 100%;" @change="changeDeptId" clearable>
								<el-option
									v-for="item in options.managerDeptIds"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item :label="$t('course.college')">
							<el-select v-model="queryForm.college" style="width: 100%;" clearable>
								<el-option
									v-for="item in options.college"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8" v-if="isGraduate">
						<el-form-item :label="$t('label.trainingLevel')">
							<el-select v-model="queryForm.trainingLevel" style="width: 100%;" clearable>
								<el-option
									v-for="item in options.trainingLevel"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8" v-if="isGraduate">
						<el-form-item :label="$t('course.courseProperty')">
							<el-select v-model="queryForm.nature" style="width: 100%;" @change="changeNatureForm" clearable>
								<el-option
									v-for="item in options.nature"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8" v-if="isUnderGraduate">
						<el-form-item :label="$t('course.isPublicChooseCourse')">
							<el-select v-model="queryForm.isElective" style="width: 100%;" clearable>
								<el-option
									v-for="item in options.isElective"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8" v-if="isGraduate">
						<el-form-item :label="$t('course.courseCategory')">
							<el-select
								v-model="queryForm.label"
								style="width: 100%;"
								:placeholder="$t('course.selectProperty')"
								clearable
							>
								<el-option
									v-for="item in options.newLabel"
									:key="item.value"
									:label="item.label"
									:value="item.value"
									:style="{textIndent:item.indent+'px'}"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8" v-if="isGraduate">
						<el-form-item :label="$t('course.teachingLanguage')">
							<el-select v-model="queryForm.teachingLanguage" clearable style="width: 100%;">
								<el-option
									v-for="item in options.teachingLanguage"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>					
					<el-col :span="8" v-if="isGraduate">
						<el-form-item :label="$t('开课学期')">
								<DictSelect
                                v-model="queryForm.term"
                                :data="options.term"
								:plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
					<el-col :span="8" v-if="isGraduate">
						<el-form-item :label="$t('是否跨院系课程')">
								<DictSelect
                                v-model="queryForm.crossCollege"
                                :data="options.enabled"
                                :plzSelect="true"
                            ></DictSelect>
						</el-form-item>
					</el-col>
				</el-row>
			</condition-card>
			<el-card shadow="never">
				<div class="edu-page-title" style="margin-bottom: 16px">{{$t("course.courseQuery")}}</div>
				<div class="edu-opertion-bar" v-if="isEnable" style="margin-bottom: 16px">
					<div class="float-left">
						<el-input
							v-model="queryForm.condition"
							:placeholder="$t('course.inputCourseTip')"
							style="width:240px"
							@keyup.enter.native="onSubmit"
						>
							<i
								class="el-icon-search"
								slot="suffix"
								style="margin-top:10px;cursor:pointer"
								@click="onSubmit"
							></i>
						</el-input>
					</div>
					<div class="float-right">
						<export-button v-if="!this.global.isStudent && isGraduate " :queryForm="queryForm" :chooseCourses="chooseCourses" exType="1">{{$t("导出PDF")}}</export-button>
						<export-button v-if="!this.global.isStudent && isGraduate " :queryForm="queryForm" :chooseCourses="chooseCourses" exType="2">{{$t("导出Word")}}</export-button>
						<el-button  @click="exportExcel" v-if="!this.global.isStudent && isGraduate">{{$t("message.export")}}</el-button>
						<el-button  @click="exportExcel" type="primary" v-if="isUnderGraduate">{{$t("message.export")}}</el-button>
					</div>
				</div>
				<edu-table
					:data="courses"
					@page-change="handleCurrentChange"
					:total="queryForm.total_"
					:pageSize="queryForm.pageSize_"
					:current-page="queryForm.pageNum_"
					@selection-change="chooseCourse"
				>
					<edu-table-column :label="$t('course.college')" prop="college" width="200"/>
					<edu-table-column :label="$t('course.courseCode')" prop="code" width="120"/>
					<edu-table-column :label="$t('course.courseName')" width="240">
						<template slot-scope="props">
							<span>{{getNameByLanguage(props.row)}}</span>
						</template>
					</edu-table-column>
					<edu-table-column :label="$t('course.score')" prop="credits" :width="isGraduate?65:null"/>
					<edu-table-column :label="$t('courses.classHour')" prop="period" :width="isGraduate?65:null"/>
					<edu-table-column v-if="isGraduate" :label="$t('course.term')" prop="term" />
					<edu-table-column :label="$t('course.courseProperty')" prop="nature" v-if="isGraduate" />
					<edu-table-column :label="$t('label.totalWeek')" prop="weeks" v-if="isUnderGraduate" />
					<edu-table-column :label="$t('course.weekHour')" prop="weekHour" v-if="isUnderGraduate" />				
					<edu-table-column :label="$t('是否跨院系课程')" v-if="isGraduate" width="130" >						
						<template slot-scope="props">{{props.row.crossCollege == null?"":(props.row.crossCollege == 1?'是':'否')}}</template>
					</edu-table-column>
					<edu-table-column
						:label="$t('course.ofScheme')"
						v-if="isGraduate"
						align="center"
						width="150"

					>
						<template slot-scope="props">
							<span slot="reference" v-if="props.row.status==3">
								<el-button
									type="text"
									size="mini"
									:disabled="!props.row.code"
									@click="queryScheme(props.row.code)"
								>{{$t("course.fromCultureScheme")}}</el-button>
							</span>
							<span slot="reference" v-else>{{$t("course.fromCultureScheme")}}</span>
						</template>
					</edu-table-column>
					<edu-table-column :label="$t('message.operating')" width="60" fixed="right">
						<template slot-scope="props">
							<el-button
								type="text"
								@click="courseDetail(props.row, 'detail')"
								size="mini"
							>{{$t('shortTermApprove.check')}}</el-button>
						</template>
					</edu-table-column>
				</edu-table>
			</el-card>
		</template>

		<CourseOperation
			v-if="pathKey=='check'"
			:pathKey="pathKey"
			:options="options"
			:courseForm="courseForm"
			:heardTitle="heardTitle"
			:managerDeptId="managerDeptId"
			@back="pathKey='main'"
			:committee="true"
		></CourseOperation>

		<QuerySchemesComponent
			v-if="pathKey=='schemes'"
			:code="code"
			:heardTitle="heardTitle"
			@back="pathKey='main'"
		></QuerySchemesComponent>

		<!--本科生添加/编辑对话框-->
		<el-dialog
			:title="dialogTitle"
			width="1000px"
			class="gCourseAddDialog"
			:visible.sync="showUnderGraduateDialog"
			@close="resetUnderFormValidate()"
			:close-on-click-modal="false"
			label-suffix=":"
			v-drag-dialog
		>
			<el-form
				:model="underGraduateCourseForm"
				label-position="right"
				label-width="100px"
				ref="underGraduateCourseForm"
				label-suffix=":"
			>
				<el-row>
					<el-col :span="12">
						<el-form-item :label="$t('course.college')" prop="college">
							<el-select
								v-model="underGraduateCourseForm.college"
								style="width: 100%;"
								:disabled="readOnly"
							>
								<el-option
									v-for="item in options.college"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>	
					<el-col :span="12">
						<el-form-item :label="$t('message.name')" prop="name">
							<el-input
								v-model="underGraduateCourseForm.name"
								maxlength="50"
								@blur="checkName"
								:disabled="readOnly"
							/>
						</el-form-item>
					</el-col>				
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item :label="$t('message.nameEn')" prop="nameEn">
							<el-input v-model="underGraduateCourseForm.nameEn" maxlength="50" :disabled="readOnly" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item :label="$t('course.score')" prop="credits">
							<el-input
								v-model="underGraduateCourseForm.credits"
								maxlength="10"
								@input="calUnderGraduatePeriod"
								:disabled="readOnly"
							/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item :label="$t('course.isPublicChooseCourse')" prop="isElective">
							<el-select
								v-model="underGraduateCourseForm.isElective"
								style="width: 100%;"
								:disabled="readOnly"
							>
								<el-option
									v-for="item in options.isElective"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item :label="$t('course.weekHour')" prop="weekHour">
							<el-input v-model="underGraduateCourseForm.weekHour" maxlength="10" :disabled="readOnly" />
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item :label="$t('label.totalWeek')" prop="weeks">
							<el-input v-model="underGraduateCourseForm.weeks" maxlength="10" :disabled="readOnly" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item :label="$t('courses.classHour')" prop="period">
							<el-input v-model="underGraduateCourseForm.period" maxlength="10" :disabled="readOnly" />
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item :label="$t('courseSummary.createTime')">
							<el-input v-model="underGraduateCourseForm.createdAt"  :disabled="true" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="修改时间">
							<el-input v-model="underGraduateCourseForm.updatedAt"  :disabled="true" />
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<div class="float-right">
							<el-button @click="cancelUnderGraduateCourse">{{$t("message.close")}}</el-button>
						</div>
					</el-col>
				</el-row>
			</el-form>
		</el-dialog>
	</div>
</template>
<script>
import {
	getCourseList,
	queryScheme
} from "common/src/api/courseTemplate";
import {
	getCourseById,
	generateExcel,
	exportExcel,
	getFacultys,
	getSubjectMajorRoleByCommittee,
	getSubjectMajorCommitteeByDept
} from "common/src/api/resource/course";
import { findListByFaculty } from "common/src/api/resource/teachers";
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import CourseOperation from "./component/CourseOperation";
import QuerySchemesComponent from "./component/QuerySchemesComponent";
import examinationStudentsApi from "common/src/api/welcomeService/examinationStudents";
import ExportButton from "./component/ExportButton";
import mixin from 'common/src/mixins/index';

var defaultCourseForm = {
	code: "", //课程编码
	name: "", //课程名称
	nameEn: "", //课程名称英文
	college: "", //学院
	trainingLevel: "", //培养层次
	formLearning: "", //学习形式
	credits: "", //学分
	period: "", //课时
	label: "", //课程分类
	isElective: "",
	outlineWriter: "",
	outlineWriterEn: "",
	outlineApprover: "",
	naturePurpose: "",
	basicRequire: "",
	schedule: "", //获取课程内容与学时分配
	scheduleEn: "", //课程内容与学时分配(英文)
	experiment: "",
	establishOn: "",
	introductionCourse: "", //简介
	engIntroductionCourse: "", //英文简介
	crossCollege: 0, //是否跨学院
	crossTrainingLevel: 0, //是否本研互选（1是0否）
	cause: "",
	remark: "",
	term: "", //研究生字段，开课学期
	nature: "", //研究生字段，课程性质
	scoreType: "", //研究生字段，成绩类型
	teachingLanguage: "", //研究生字段，授课语言
	majorList: [], //研究生字段，专业中文
	majorTextI18n:null,
	//majorTextEn: "", //研究生字段，专业英文
	enabled: 1, //研究生字段，课程使用状态
	crossTerm: 0, //研究生字段，是否跨学期
	assessmentMode: "", //考试方式,
	headTeacher: null, //主讲人
	teachersList: null, //其他讲课人
	teachMode:null,
	teachModeList:null,
	teachModeI18n:null,
	subjectMajorCode:"",//学科专业委员会代码
	appointUserCode:"",//指定审核人code
	teacherTermInfo:null
};
export default {
	name: "courseQuery",
	mixins: [mixin],
	components: {
		CourseOperation,
		QuerySchemesComponent,
		ExportButton
	},
	data() {
		return {
			pathKey: "main",
			path: {
				label: this.$t("courses.courseManagement"),
				key: "belong",
				disable: true,
				children: [
					{
						label: this.$t("courses.courseQuery"),
						key: "main",
						children: [
							{
								label: this.$t("courses.courseDetails"),
								key: "check"
							},
							{
								label: this.$t("courses.courseSchemes"),
								key: "schemes"
							}
						]
					}
				]
			},
			code: "",
			isUnderGraduate: false,
			isGraduate: false,
			courseStatus: {
				DISABLE: 0,
				DRAFT: 1,
				CHECKING: 2,
				PUBLISH: 3
			},
			cachmanagerDeptId:"",
			queryForm: {
				teachingLanguage: "",
				college: [], //学院 支持多选
				trainingLevel: "", //培养层次
				formLearning: "", //学习形式
				nature: "", //课程性质
				isElective: "", //公共选修课
				label: "", //课程分类
				enabled: "1", //是否使用
				condition: "", //课程代码或课程名称
				status: 3,
				pageSize_: 20,
				pageNum_: 1,
				total_: 0,
				managerDeptId: "",
				term:"",//开课学期
				approvalFlag: "3",
				crossCollege:""//是否跨院系课程
			},
			courseForm: JSON.parse(JSON.stringify(defaultCourseForm)),
			underGraduateCourseForm: {
				college: "",
				trainingLevel: "",
				name: "",
				nameEn: "",
				credits: "",
				isElective: 0,
				weekHour: "",
				weeks: "",
				period: "",
				checked: true,
				managerDeptId: 1,
				createdAt:null,
				updatedAt:null
			},
			options: {
				college: [],
				trainingLevel: [],
				formLearning: [],
				nature: [], //课程性质
				isElective: [], //公共选修课，（1或0)
				label: [], //课程分类
				newLabel: [],
				crossCollege: [], //是否跨学院（1是0否）
				crossTrainingLevel: [], //是否本研互选（1是0否）
				term: [],
				scoreType: [], //成绩类型
				teachingLanguage: [], //授课类型
				enabled: [], //研究生字段，课程使用状态
				crossTerm: [], //研究生字段，是否跨学期
				dialogLabelId: [], //弹框的课程分类
				assessmentMode: [], //考试方式
				majorList: [],
				teacherList: [],
				managerDeptIds:[],
				allTrainingLevel:[],//作一个缓存
				appointUserCode:[],
				subjectMajorCode:[]
			},
			courses: [], //课程列表
			schemes: [], //培养方案列表
			chooseCourses: [], //选中课程列表
			editCourseId: "", //当前编辑课程Id
			dialogTitle: "",
			isEnable: false,
			readOnly: false,
			showUnderGraduateDialog: false, //本科生对话框
			headTeacherCondition: null,
			teacherCondition: null,
			manageDptIds:[]			
		};
	},
	mounted() {
		let user = this.global.currentUser;
		if (this.global.isAnyTeacher) {
			this.manageDptIds =  user.manageDptIds;
			if(this.manageDptIds.length>0){
				this.isGraduate = this.manageDptIds[0] != "1";
				this.isUnderGraduate =  this.manageDptIds[0]== "1";
				this.cachmanagerDeptId =  this.manageDptIds[0]
			}
		}else{
			this.isGraduate = user.currentManageDptId != "1";
			this.isUnderGraduate = user.currentManageDptId == "1";			
		}
		this.init();
	},
	watch:{
		'queryForm.managerDeptId' (val,oldVal) {
			this.isGraduate = this.queryForm.managerDeptId != "1"
			this.isUnderGraduate = this.queryForm.managerDeptId == "1"
			this.options.newLabel.length = 0;
			this.queryForm.formLearning = "";
			this.queryForm.nature = "";
			this.queryForm.isElective = "";
			this.queryForm.label = "";
			this.queryForm.teachingLanguage = "";
			this.queryForm.term ="";
			this.queryForm.crossCollege =""
			//重置培养层次的选项
			if(oldVal == 1 && val != 1){
				this.queryForm.trainingLevel = ""
			}
			if(oldVal != 1 && val == 1){
				this.queryForm.trainingLevel = ""
			}
			this.onSubmit()
		}
	},
	methods: {
		init() {			
			let yes = {
					label: this.$t("message.yes"),
					value: 1
				},
				no = {
					label: this.$t("message.no"),
					value: 0
				};
			this.options.isElective.push(yes);
			this.options.isElective.push(no);
			this.options.crossCollege.push(yes);
			this.options.crossCollege.push(no);
			this.options.crossTrainingLevel.push(yes);
			this.options.crossTrainingLevel.push(no);
			this.options.enabled.push(yes);
			this.options.enabled.push(no);
			this.options.crossTerm.push(yes);
			this.options.crossTerm.push(no);
			//筛选条件字典查询
			let data = {
				lang: this.$store.getters.language || "cn",
				type: "allChild",
				keys: [
					"X_PYCC",
					// "X_YX",
					"X_XXXS",
					"X_CJJL",
					"X_SKYY",
					"X_KKXQ",
					"X_KSLX",
					"G_ZY",
					"X_KCXZ",
					"X_KCFL",
					"X_JXFS",
					"X_GLBM"
				]
			};
			queryDic(data).then(res => {
				if (res.code == 200) {
					UTILS.fillSelect(
						{
							trainingLevel: "X_PYCC",
							// college: "X_YX",
							formLearning: "X_XXXS",
							scoreType: "X_CJJL",
							teachingLanguage: "X_SKYY",
							term: "X_KKXQ",
							assessmentMode: "X_KSLX",
							majorList: "G_ZY",
							nature: "X_KCXZ",
							label: "X_KCFL",
							teachModeList: "X_JXFS",
							managerDeptIds:"X_GLBM",
							allTrainingLevel: "X_PYCC"
						},
						res.data,
						this.options
					);
					this.isEnable = true;
					if(this.global.isAnyTeacher){
						this.options.managerDeptIds=this.options.managerDeptIds.filter(dept=>{
							return this.manageDptIds.includes(dept.value)
						})
						if(this.queryForm.managerDeptId == '1'){
							this.options.trainingLevel = this.options.allTrainingLevel.filter(tr =>{
								return tr.value != '4' && tr.value != '6'
							})
						}else{
							this.options.trainingLevel = this.options.allTrainingLevel.filter(tr =>{
								return tr.value == '4' || tr.value == '6'
							})
						}
					}
					this.$nextTick(re =>{
						this.queryForm.managerDeptId = this.cachmanagerDeptId
						this.onSubmit();
					})
				}	
			});
			//查询开课学院
			getFacultys(this.isGraduate).then(res => {
				if (res.code == 200) {
					let depts =res.data.filter(c => c.deptCode != "-10000");
					this.options.college = depts;
					this.options.college.forEach(c => {
						c.value = c.deptCode;
						c.label =
							"en" == this.$store.getters.language
								? c.deptNameEn
								: c.deptName;
					});
				}
			});
		},
		reset() {
			this.options.newLabel.length = 0;
			this.queryForm.college = [];
			this.queryForm.trainingLevel = "";
			this.queryForm.formLearning = "";
			this.queryForm.nature = "";
			this.queryForm.isElective = "";
			this.queryForm.label = "";
			this.queryForm.condition = "";
			this.queryForm.teachingLanguage = "";
			this.queryForm.term ="";
			this.queryForm.crossCollege =""
			this.onSubmit();
		},
		onSubmit() {
			this.getCourseList();
		},
		handleCurrentChange(val) {
			this.queryForm.pageNum_ = val.pageNum;
			this.queryForm.pageSize_ = val.pageSize;
			this.getCourseList();
		},
		//获取课程列表
		getCourseList() {
			//facultys:支持多选所传参数,兼容之前数据类型,采用loadsh的 omit 方法移除原来college属性
			const params = _.omit(
				Object.assign(this.queryForm, {
					facultys: this.queryForm.college
				}),
				["college"]
			);
			if(params.facultys.length < 1){
				params.facultys = null;
			}
			getCourseList(params).then(response => {
				if (response.code == 200) {
					this.courses = response.data.list;
					this.queryForm.total_ = response.data.total_;
				} else {
					throw response.code;
				}
			});
		},
		chooseCourse(val) {
			this.chooseCourses = val;
		},
		courseDetail(row, type) {
			this.dialogTitle = this.$t("course.courseDetails");
			this.readOnly = true;
			this.editCourseId = row.id;
			//获取该课程详细信息
			getCourseById(this.editCourseId).then(response => {
				if (response.code == 200) {
					if (this.isUnderGraduate) {
						Object.keys(this.underGraduateCourseForm).forEach(
							key => {
								if (response.data[key] || response.data[key] === 0) {
									this.underGraduateCourseForm[key] =
										response.data[key];
								}else {
									this.underGraduateCourseForm[key] = "";	
								}
							}
						);
						this.underGraduateCourseForm["isElective"] =
							response.data["isElective"];
						this.showUnderGraduateDialog = true;
					} else {
						this.changeNatureEdit(response.data.nature);
						this.changeSubMajor(response.data.subjectMajorCode);
						//查询专业学科委员会
						getSubjectMajorCommitteeByDept(response.data.college).then(res =>{
							if (res.code == 200 && res.data.length > 0) {
								for (const item of res.data) {
									this.options.subjectMajorCode.push({
										label: item.subjectMajorName,
										value: item.subjectMajorCode
									});
								}
							}
						});
						Object.keys(this.courseForm).forEach(key => {
							if (response.data[key] || response.data[key] === 0) {
								this.courseForm[key] = response.data[key];
							}else {
								this.courseForm[key] = "";	
							}
						});
						this.courseForm["isElective"] =
							response.data["isElective"];
						if (this.courseForm.college) {
							this.changeDialogCollege(this.courseForm.college);
						}
						this.headTeacherCondition = {
							codeList: this.courseForm.headTeacher
						};
						this.teacherCondition = {
							codeList: this.courseForm.teachersList
						};
						this.pathKey = "check";
						if (type == "edit") {
							this.heardTitle = this.$t("course.updateCourse");
							this.pathKey = "edit";
						} else if (type == "detail") {
							this.heardTitle = this.$t("course.courseDetails");
							this.pathKey = "check";
						}
					}
				}
			});
		},
		//培养方案
		queryScheme(code) {
			this.pathKey = "schemes";
			this.heardTitle = this.$t("course.ofScheme");
			this.code = code;
		},
		changeSubMajor(val){
            this.options.appointUserCode = [];
            if(val){
                getSubjectMajorRoleByCommittee(val).then(res =>{
                    if (res.code == 200 && res.data.length > 0) {
                        for (const item of res.data) {
                            this.options.appointUserCode.push({
                                label: item.userName+'('+item.userCode+')',
                                value: item.userCode
                            });
                        }
                    }
                })
            }
        },
		changeNatureEdit(val) {
			this.options.tableLabel = [];
			let obj = [];
			let labels = this.options.label;
			labels.forEach(item => {
				if (val == "1") {
					if (
						item.value == "01" ||
						item.value == "02" ||
						item.value == "03" ||
						item.value == "07"
					) {
						obj.push({ label: item.label, value: item.value });
					}
				} else if (val == "2") {
					if (
						item.value == "04" ||
						item.value == "05" ||
						item.value == "06" ||
						item.value == "07"
					) {
						obj.push({ label: item.label, value: item.value });
					}
				} else {
					if (item.value == "08" || item.value == "09") {
						obj.push({ label: item.label, value: item.value });
					}
				}
			});
			this.options.tableLabel = obj;
		},
		changeNatureForm(val) {
			this.options.newLabel = [];
			this.queryForm.label = "";
			let obj = [];
			let labels = this.options.label;
			labels.forEach(item => {
				if (val == "1") {
					if (
						item.value == "01" ||
						item.value == "02" ||
						item.value == "03" ||
						item.value == "07"
					) {
						obj.push({ label: item.label, value: item.value });
					}
				} else if (val == "2") {
					if (
						item.value == "04" ||
						item.value == "05" ||
						item.value == "06" ||
						item.value == "07"
					) {
						obj.push({ label: item.label, value: item.value });
					}
				} else {
					if (item.value == "08" || item.value == "09") {
						obj.push({ label: item.label, value: item.value });
					}
				}
			});
			this.options.newLabel = obj;
		},
		exportExcel() {
			let loading = this.$loading({
				lock: true,
				text: "Loading",
				spinner: "el-icon-loading",
				background: "rgba(255, 255, 255, .48)"
			});
			let data=_.cloneDeep(this.queryForm);
            data.idSet = this.chooseCourses.map(c => c.id);
			//facultys:支持多选所传参数,兼容之前数据类型,采用loadsh的 omit 方法移除原来college属性
			const params = _.omit(
				Object.assign(data, {
					facultys:data.college
				}),
				["college"]
			);
			if(params.facultys.length < 1){
				params.facultys = null;
			}
			generateExcel(params).then(res => {
				if (res.code == 200) {
					this.delayRequest(res.data.key, loading);
				}
			});
		},		
		async delayRequest(key, loading) {
			await new Promise(resolve => setTimeout(resolve, 5000));
			examinationStudentsApi.getReportStatus(key)
				.then(res => {
					if (res.code == 200 && res.data.status) {
						loading.close();
						 let path = examinationStudentsApi.exportUrl + res.data.path;
                        window.location.href = path;
						//window.open(path);
					} else {
						this.delayRequest(key, loading);
					}
				})
				.catch(err => {
					loading.close();
					throw err;
				});
		},
		getYesOrNoByValue(val) {
			let lang = this.$store.getters.language || "cn";
			if (lang == "cn") {
				return val == 1 ? "是" : "否";
			} else {
				return val == 1 ? "Yes" : "No";
			}
		},
		getNameByLanguage(obj) {
			let lang = this.$store.getters.language || "cn";
			if (lang == "cn") {
				return obj.name;
			} else {
				return obj.nameEn;
			}
		},
		changeDialogCollege(val) {
			findListByFaculty({ faculty: val }).then(res => {
				this.options.teacherList = res.data;
			});
		},
		//取消本科生课程对话框
		cancelUnderGraduateCourse() {
			this.showUnderGraduateDialog = false;
		},
		resetUnderFormValidate() {
			this.underGraduateCourseForm.college = "";
			this.underGraduateCourseForm.trainingLevel = "";
			this.underGraduateCourseForm.name = "";
			this.underGraduateCourseForm.nameEn = "";
			this.underGraduateCourseForm.credits = "";
			this.underGraduateCourseForm.period = "";
			this.underGraduateCourseForm.isElective = 0;
			this.underGraduateCourseForm.weekHour = "";
			this.underGraduateCourseForm.weeks = "";
			this.underGraduateCourseForm.checked = true;
			this.underGraduateCourseForm.createdAt = "";
			this.underGraduateCourseForm.updatedAt = "";
		},
		changeDeptId(val){
			if(val == '1'){
				this.options.trainingLevel = this.options.allTrainingLevel.filter(tr =>{
					return tr.value != '4' && tr.value != '6'
				})
			}else{
				this.options.trainingLevel = this.options.allTrainingLevel.filter(tr =>{
					return tr.value == '4' || tr.value == '6'
				})
			}
		}
	}
};
</script>

<style lang="scss">
.gCourseAddDialog {
	div.el-dialog__body {
		max-height: 400px;
		overflow: auto;
	}
	.el-col {
		padding-left: 10px;
		padding-right: 10px;
	}
}
</style>

